package pb

import (
	"packet"
)

// RoleLogin 请求登录
type RoleLogin struct {
	Account                  string //账号
	Password                 string //密码
	Remark                   string //备注
	Video                    []byte //语音
}

func (this *RoleLogin) Encode() []byte {
	pack := this.encode()
	return pack.Encode(uint16(1010))
}

func (this *RoleLogin) EncodeMsg() []byte {
	pack := this.encode()
	return pack.ReadBytes()
}

func RoleLoginDecode(pack *packet.Packet) *RoleLogin {
	roleLogin := &RoleLogin{}

	roleLogin.Account = pack.ReadString()
	roleLogin.Password = pack.ReadString()
	RemarkFlag := pack.ReadUint8()
	if RemarkFlag == 1 {
		roleLogin.Remark = pack.ReadString()
	}
	VideoFlag := pack.ReadUint8()
	if VideoFlag == 1 {
		roleLogin.Video = pack.ReadBin()
	}

	return roleLogin
}

func (this *RoleLogin) encode() *packet.Packet {
	pack := packet.NewWriteBuff(64)

	pack.WriteString(this.Account)
	pack.WriteString(this.Password)
	if this.Remark != "" {
		pack.WriteUint8(1)
		pack.WriteString(this.Remark)
	} else {
		pack.WriteUint8(0)
	}
	if this.Video != nil {
		pack.WriteUint8(1)
		pack.WriteBin(this.Video)
	} else {
		pack.WriteUint8(0)
	}

	return pack
}
